<template>
  <div class="box">
    <h2>会员管理页面</h2>
    <el-table :data="member.memberList" width="100%">
      <el-table-column label="序号" prop="id" width="80"> </el-table-column>
      <el-table-column label="手机号" prop="phone" width="200">
      </el-table-column>
      <el-table-column label="昵称" prop="nickname"> </el-table-column>
      <el-table-column label="账号状态" prop="status">
        <template v-slot="props">
          <el-tag type="success" size="small" v-if="props.row.status === 1"
            >启用</el-tag
          >
          <el-tag type="danger" size="small" v-else>禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="180">
        <template v-slot="props">
          <el-button
            type="primary"
            size="small"
            round
            @click="editMember(props.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="member.page"
      v-model:page-size="member.size"
      :page-sizes="[1, 3, 5, 10, 20, 50, 100]"
      small
      :total="member.total"
      background
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="changeSize"
      @current-change="changePage"
    />
    <!-- 弹窗 -->
    <Dialog ref="VDialog"></Dialog>
  </div>
</template>

<script setup>
import { ElMessage, ElMessageBox } from "element-plus";
import { ref, reactive, onMounted } from "vue";
import { useRouter } from "vue-router";
// 导入弹窗组件
import Dialog from "./dialog.vue";
// 导入store
import useMemberStore from "../../stores/member";
// 定义
const member = useMemberStore();

onMounted(() => {
  // 调用函数,获取数据
  member.getMemberListAction();
  member.getMemberTotalAction();
});

// 分页相关函数
function changeSize(size) {
  member.CHANGE_SIZE(size);
  member.getMemberListAction();
}
function changePage(page) {
  // console.log(page);
  member.CHANGE_PAGE(page);
  member.getMemberListAction();
}

// 弹窗变量
const VDialog = ref(null);
// 打开弹窗
const showDialog = () => {
  VDialog.value.dialogVisible = true;
  // console.log(VDialog.value.dialogVisible);
};

// 编辑
function editMember(Member) {
  // console.log("11111111111111", VDialog.value, Member.id);
  // 显示弹窗，将数据发送给子组件
  VDialog.value.acceptValue(Member);
  showDialog();
}
</script>

<style lang="css" scoped>
.el-pagination {
  margin-top: 20px;
  justify-content: center;
}
</style>
